package com.jwthhealth_pub.old.common.location;

import android.content.Context;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;

/**
 * 百度定位
 * Created by Administrator on 2017/8/28.
 */

public class BaiduLocation implements BDLocationListener {
    private LocationClient mLocationClient;
    private final BDLocacionReceiver mBdLocationReceiver;

    public BaiduLocation(Context context, BDLocacionReceiver bdLocacionReceiver) {
        mLocationClient = new LocationClient(context);
        mBdLocationReceiver = bdLocacionReceiver;
        InitLocation();
    }

    private void InitLocation() {
        LocationClientOption option = new LocationClientOption();
        //设置定位模式为高精度,默认高精度
//        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
        //设置返回经纬度坐标类型,默认gcj02（国测局坐标）
//        option.setCoorType("bd09ll");
        //设置发起定位请求的间隔， 1s
        option.setScanSpan(1000);
        //是否使用gps, 高精度模式必须开启
        option.setOpenGps(true);
        //不收集Crash信息
        option.SetIgnoreCacheException(true);
        //获取城市信息
        option.setIsNeedAddress(true);
        mLocationClient.setLocOption(option);
        mLocationClient.registerLocationListener(this);
        mLocationClient.start();
    }

    @Override
    public void onReceiveLocation(BDLocation bdLocation) {
        mLocationClient.stop();
        mBdLocationReceiver.onReceiverLocation(bdLocation);
    }

//    @Override
//    public void onConnectHotSpotMessage(String s, int i) {
//        LogUtil.i(s, BaiduLocation.class.getName());
//        LogUtil.i(i+"", BaiduLocation.class.getName());
//    }

    public interface BDLocacionReceiver {
        void onReceiverLocation(BDLocation location);
    }
}
